package com.zqwh.xtool.model.online;

import android.content.Context;

import com.zqwh.yj.sdk.utils.httpRequest.RetrofitSingleton;
import com.zqwh.yj.sdk.utils.httpRequest.subscribers.NetCallback;
import com.zqwh.yj.sdk.utils.httpRequest.subscribers.ProgressSubscriber;
import com.zqwh.yj.sdk.utils.httpRequest.HttpResultFunc2;
import com.zqwh.xtool.api.online.HeartbeatApi;
import com.zqwh.xtool.config.BaseConfig;
import com.zqwh.xtool.domain.Msg;
import com.zqwh.xtool.model.HeartbeatModel;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class HeartbeatModelOnlineImpl implements HeartbeatModel {
    private HeartbeatApi heartbeatApi;
    private Context context;

    public HeartbeatModelOnlineImpl(Context context) {
        this.context = context;
        this.heartbeatApi = RetrofitSingleton.getInstance(BaseConfig.BASE_URL).create(HeartbeatApi.class);
    }
    @Override
    public void heartbeat(Long devId, NetCallback<Msg> callback) {
        heartbeatApi.heartbeat(devId)
                .map(new HttpResultFunc2<Msg>())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber(callback, context, false));
    }
}
